home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / delphi1 / lesson2 / conv2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-11  |  1.3 KB  |  60 lines

  1. unit Conv2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TConv2Form = class(TForm)
  11.     ConvertFromEd: TEdit;
  12.     ConvertToEd: TEdit;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     CalcBtn: TButton;
  16.     GroupBox1: TGroupBox;
  17.     KmToMilesRBtn: TRadioButton;
  18.     MilesToKmRBtn: TRadioButton;
  19.     CToFRBtn: TRadioButton;
  20.     FToCRBtn: TRadioButton;
  21.     procedure CalcBtnClick(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   Conv2Form: TConv2Form;
  30.  
  31. implementation
  32.  
  33. {$R *.DFM}
  34.  
  35. procedure TConv2Form.CalcBtnClick(Sender: TObject);
  36. const
  37.      milesToKM = 1.60934;
  38.      KMToMiles = 0.62137;
  39. var
  40.    InputVal, OutputVal : Real;
  41.    Code : integer;
  42.    S : string;
  43. begin
  44.    Val(ConvertFromEd.Text, InputVal, Code );
  45.    If KmToMilesRBtn.checked then
  46.          OutputVal := InputVal * KmToMiles
  47.    else if MilesToKmRBtn.checked then
  48.          OutputVal := InputVal * milesToKM
  49.    else if CToFRBtn.checked then
  50.          OutputVal := ((InputVal * 9) / 5) + 32
  51.    else if FToCRBtn.checked then
  52.          OutputVal := ((InputVal -32) * 5) /9;
  53.    
  54.  
  55.    Str( OutputVal:2:2, S );
  56.    ConvertToEd.Text :=  S;
  57. end;
  58.  
  59. end.
  60.